/*
 * Copyright (c) 2002-2003 by OpenSymphony
 * All rights reserved.
 */
package org.jackysoft.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.jackysoft.data.IDataProvider;
import org.jackysoft.entity.FieldAccess;
import org.jackysoft.entity.HibernateCurrentStep;
import org.jackysoft.entity.HibernateHistoryStep;
import org.jackysoft.entity.HibernateWorkflowEntry;
import org.jackysoft.entity.OfficeDocument;
import org.jackysoft.entity.Step;
import org.jackysoft.entity.User;
import org.jackysoft.entity.WorkflowEntry;
import org.jackysoft.opensymphony.workflow.entity.WorkflowDescriptor;
import org.jackysoft.util.WorkflowConstant;
import org.springframework.dao.DataAccessException;


public interface WorkflowService extends IDataProvider<Long,WorkflowEntry>{
	
	
	
    //~ Methods ////////////////////////////////////////////////////////////////

	public static final ThreadLocal<WorkflowConstant> LOCAL_STATUS = new ThreadLocal<WorkflowConstant>();
	public static final ThreadLocal<Long> CURRENT_WORKFLOWID = new ThreadLocal<Long>();
	void setReload(boolean reaload);
	
	void setValidate(boolean validate);
	
	void setForceReload(boolean load);
	
  
    public void setEntryState(long entryId, int state) throws DataAccessException;

    
   
    public Step createCurrentStep(long entryId, int stepId, int actionId,String owner, Date startDate, Date dueDate, String status, long[] previousIds) throws DataAccessException;

    /**
     * Persists a new workflow entry that has <b>not been initialized</b>.
     *
     * @param workflowName the workflow name that this entry is an instance of
     * @return a representation of the workflow instance persisted
     */
    public WorkflowEntry createEntry(String workflowName) throws DataAccessException;

    /**
     * Returns a list of all current steps for the given workflow instance ID.
     *
     * @param entryId The workflow instance id.
     * @return a List of Steps
     * @see org.jackysoft.entity.spi.Step
     */
    public List findCurrentSteps(long entryId) throws DataAccessException;
    public boolean stepInStatus(int stepId,String status)throws DataAccessException;

    /**
     * Pulls up the workflow entry data for the entry ID given.
     *
     * @param entryId The workflow instance id.
     * @return a representation of the workflow instance persisted
     */
    public WorkflowEntry findEntry(long entryId) throws DataAccessException;
    
    /**
     * stepID
     * */
    public HibernateHistoryStep loadHistoryStep(Long id) throws DataAccessException;
    public HibernateCurrentStep loadCurrentStep(Long id) throws DataAccessException;
    
    /**
     * Returns a list of all steps that are finished for the given workflow instance ID.
     *
     * @param entryId The workflow instance id.
     * @return a List of Steps
     * @see org.jackysoft.entity.spi.Step
     */
    public List findHistorySteps(long entryId) throws DataAccessException;

    /**
     * Called once when the store is first created.
     *
     * @param props properties set in osworkflow.xml
     */
    public void init() throws DataAccessException;
    public Map<String ,WorkflowDescriptor> getWorkflowCaches();
    /**
     * Mark the specified step as finished.
     * @param step the step to finish.
     * @param actionId The action that caused the step to finish.
     * @param finishDate the date when the step was finished.
     * @param status The status to set the finished step to.
     * @param caller The caller that caused the step to finish.
     * @return the finished step
     */
    public Step markFinished(Step step, int actionId, Date finishDate, String status, String caller) throws DataAccessException;

    /**
     * Called when a step is finished and can be moved to workflow history.
     *
     * @param step the step to be moved to workflow history
     */
    public void moveToHistory(Step step) throws DataAccessException;
  
    /**
     * 
     * 
     * */
    void modifyWorkflow(HibernateWorkflowEntry entry);
    /**
     * 
     * 
     * */
    void deleteWorkflow(long id);
    /**
     * 
     * 
     * */
    void completeWorkflow(long id);
    /**
     * 
     * 把该工作流回退一步
     * @param id 工作流实例编号 
     * 
     * */
    void rollbackWorkflow(long id);
    /**
     * 
     * 
     * */
    User getActor(String name);
           
    //
          
    WorkflowDescriptor getWorkflowDescriptor(String name);
    
    String[] getWorkflowNames();    
  
    void setWorkflowVariableService(VariableService workflowVariableService);
    
    void removeCurrentStep(HibernateCurrentStep step);
        
    //office document operation 
    
    void updateDocument(byte[] data,long  entityId) throws DataAccessException;
    
    OfficeDocument getOffice(long workflowId) throws DataAccessException;
    
    void collate(byte[] data,String ext,long entityId) throws DataAccessException;
    
    FieldAccess getFieldAccess(long workflowId,int stepId);
}
